package com.hall.utils;

import com.hall.pojo.SysUser;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public final class UserSession {
    public final static String SESSION_USER = "userId";
    public static SysUser getSysUser(HttpServletRequest request) {
        SysUser sysUser = new SysUser();
        if(request.getSession(false)==null){
            return sysUser;
        }
        HttpSession session1 = request.getSession();
        ServletContext Context = session1.getServletContext();
        ServletContext Context1 = Context.getContext("/boke");
        if (Context1 != null) {
            HttpSession sess = (HttpSession) Context1.getAttribute(session1.getId());
            if (sess == null) return sysUser;
            try {
            String[] user = (String[]) sess.getAttribute(SESSION_USER);
            if (user!=null) {
                sysUser.setId(user[0]);
                sysUser.setUsertype(user[1]);
                sysUser.setLoginName(user[2]);
                return sysUser;
            }
            }catch (IllegalStateException e){
                return sysUser;
            }
        }
        return sysUser;
    }
}

